package org.fatmansoft.teach.repository;

import org.fatmansoft.teach.models.HomeWork;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Optional;

public interface HomeWorkRepository extends JpaRepository<HomeWork, Long> {

    @Query(value = "select max(homeWorkId) from HomeWork ")
    Integer getMaxId();

    @Query(value ="from HomeWork where ?1='' or homeWorkName like %?1% or homeWorkTime like %?1% ")
   List<HomeWork> findHomeWorkByNameTime(String nameTime);

    @Query(value ="from HomeWork where homeWorkName like %?1% and homeWorkTime like %?2% ")
   Optional<HomeWork> findHomeWorkByHomeWorkNameAndHomeWorkTime(String name, String time);

    Optional<HomeWork> findByHomeWorkId(Integer homeWorkId);

    Optional<HomeWork> findByHomeWorkName(String homeWorkName);
}
